package com.zhb.cloud.service.impl;

import com.alibaba.dubbo.config.annotation.Reference;
import com.zhb.cloud.core.JsonReturn;
import com.zhb.cloud.hystrix.command.CustomerHystrixCommand;
import com.zhb.cloud.iservice.IUserService;
import com.zhb.cloud.service.UserService;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

/**
 * @ClassName: MyCityServiceImpl
 * @author: zhb
 * @date: 2017年8月8日 下午2:57:59
 * @Description: 实际服务的发起
 *
 */
@Service
public class UserServiceImpl implements IUserService {
	@Reference(version = "1.0.0")
	private UserService userService;

	/**
	 * @Title: findByUserName
	 * @author: zhb
	 * @date: 2017年8月9日 下午4:25:01
	 * @Description: 使用注解做熔断处理--实际做法(创建hystrixCommand来进行操作)
	 * @param userName
	 * @return
	 */
	@Override
	public JsonReturn findByUserName(String userName) throws Exception {
		Map<String, Object> map = new HashMap<>();
		map.put("service", userService);
		map.put("userName", userName);
		Map<String, Object> retMap = new CustomerHystrixCommand(map).execute();
		JsonReturn jsonReturn = new JsonReturn();
		jsonReturn.setCode(Integer.parseInt(retMap.get("code").toString()));
		jsonReturn.setData(retMap.get("data"));
		jsonReturn.setMessage(retMap.get("message").toString());
		return jsonReturn;
	}
}
